<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>用户注册</title>
		<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport" />
		<meta content="yes" name="apple-mobile-web-app-capable" />
		<meta content="black" name="apple-mobile-web-app-status-bar-style" />
		<meta content="telephone=no" name="format-detection" />
		<link rel="stylesheet" type="text/css" href="../css/api.css" />
		<link href="../css/stylezcy.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="../js/jqueryzcy.js"></script>
		<script type="text/javascript" src="js/time.js"></script>
				<style media="screen">
		</style>
	</head>

	<body>
		<header class="ui_button"></header>
		<section class="aui-flexView">
			<header class="aui-navBar aui-navBar-fixed">
				<a onclick="closeWin()" class="aui-navBar-item">
					<i class="icon icon-return"></i>
				</a>
				<div class="aui-center">
					<span class="aui-center-title">注册</span>
				</div>
				<a href="javascript:;" class="aui-navBar-item">
					<i class="icon icon-news"></i>
				</a>
			</header>

			<div class="aui-code-box">

				<p class="aui-code-line">
					<input type="text" class="aui-code-line-input" name="search" value="" id="username" autocomplete="off" placeholder="请输入手机号" />
				</p>

				<p class="aui-code-line aui-code-line-clear">
					<input id="yzcode" type="text" class="aui-code-line-input" autocomplete="off" placeholder="短信验证码" />
					<input id="btn1" type="button" class="aui-btn-default" value="获取验证码" onclick="getCode()" />
				</p>
				<p class="aui-code-line">
					<input type="text" class="aui-code-line-input" name="search" value="" id="password" autocomplete="off" placeholder="请设置密码" />
				</p>
				<p class="aui-code-line">
					<input type="text" class="aui-code-line-input" name="search" value="" id="share" autocomplete="off" placeholder="邀请码（选填）" />
				</p>
				<div class="aui-che-item">
					<div class="aui-cell-che">
						<input type="checkbox" class="aui-well-check" name="checkbox1" id="" checked="checked">
						<i class="aui-well-icon-checked"></i>
					</div>我已经阅读并同意 <a href="javascript:;">《通霸云影视注册协议条款》</a>
				</div>
				<div class="aui-code-btn">
					<button onclick="toReg()">注册</button>
				</div>

			</div>

		</section>
		<script type="text/javascript" charset="utf-8">
			$(function() {

				$(".aui-code-line-input").addClear();

			});
		</script>
	</body>


	<script type="text/javascript" src="../script/api.js"></script>
	<script type="text/javascript">
		var api_url = localStorage.getItem('api_url');
		var onoff = true;
		var code_data;
		var user;
		var pass;
		apiready = function() {
			$api.fixIos7Bar($api.dom("header"));
			api.parseTapmode();
			var header = $api.byId('aui-header');
			$api.fixStatusBar(header);
			var headerPos = $api.offset(header);
			var body_h = $api.offset($api.dom('body')).h;

		}




		//去注册
		function toReg() {
			var username = $api.val($api.byId('username'));
			var password = $api.val($api.byId('password'));
			var yzcode = $api.val($api.byId('yzcode'));
			var share = $api.val($api.byId('share'));
			if (username == '') {
				api.toast({
					msg: '通霸云影视提醒！账号都没输入',
				});
				return;
			}
			if (password == '') {
				api.toast({
					msg: '通霸云影视提醒！密码还没输入',
				});
				return;
			}

			if (username.length < 6) {
				api.toast({
					msg: ' 请输入6位数以上账号 ',
				});
				return;
			}
			var moduleSMSSDK = api.require('smssdk');
			var param = {
				zone: '86',
				phoneNumber: username,
				code: yzcode
			};
			moduleSMSSDK.commitCode(param, function(ret, err) {
				if (err !== null && err !== undefined && err !== '') {
					// 错误消息示例：{"msg":"Template not exist.","code":484}
					alert("Error:\n" + JSON.stringify(err));
				} else {
					api.toast({
						msg: ' 注册中 请稍等…… ',
					});
					api.ajax({
						url: api_url + 'login/login/create1.html',
						method: 'get',
						data: {
							values: {
								name: username,
								password: password,
								share_ma: share,
								type: 'App独立注册',
								shibie: api.deviceId,
								imei: api.deviceId,
								key:localStorage.getItem('anq_key'),
							}
						}
					}, function(ret, err) {
						if (ret) {
							if (ret.code == 0) {
								api.hideProgress();
								api.alert({
									title: '错误~',
									msg: ret.msg,
								});
							} else {
								//api.hideProgress();
								api.alert({
									title: '注册成功！',
									msg: '当前身份：体验会员',
								});
								//openLogin();
								api.ajax({
									url: api_url + 'login/login/logo.html',
									method: 'get',
									data: {
										values: {
											username: username,
											passwd: password,
											imei: api.deviceId,
											key:localStorage.getItem('anq_key'),
										}
									}
								}, function(ret, err) {
									if (ret) {
										console.log(JSON.stringify(ret));
										//alert( JSON.stringify( ret.msg['id'] ) );
										localStorage.setItem('accountLogin', 0);
										localStorage.setItem('user_id', ret.msg['id']);
										localStorage.setItem('user_name', username);
										localStorage.setItem('password', password);
										localStorage.setItem('user_time', ret.msg['time']);
										localStorage.setItem('user_share', ret.msg['share']);
										localStorage.setItem('user_advert', ret.msg['advert']);
										localStorage.setItem('user_code', ret.msg['code']);
										localStorage.setItem('power', ret.msg['power']);
										localStorage.setItem('url', ret.msg['url']);
										localStorage.setItem('url1', ret.msg['url1']);
										localStorage.setItem('url2', ret.msg['url2']);
										localStorage.setItem('url3', ret.msg['url3']);
										localStorage.setItem('url4', ret.msg['url4']);
										localStorage.setItem('url5', ret.msg['url5']);
										localStorage.setItem('url6', ret.msg['url6']);
										localStorage.setItem('url7', ret.msg['url7']);
										localStorage.setItem('user_nickname', ret.msg['nick_name']);
										localStorage.setItem('tjryqma', ret.msg['sjyqma']);
										localStorage.setItem('stdejb', ret.msg['stjb']);
										localStorage.setItem('user_zfb', ret.msg['zfb']);
										localStorage.setItem('user_weichat', ret.msg['weichat']);
										localStorage.setItem('user_sharema', ret.msg['share_ma']);
										localStorage.setItem('user_img', ret.msg['userimg']);
										api.sendEvent({
											name: 'newLoingdata',
											extra: {}
										});
										api.closeToWin({
											name: 'root'
										});
									} else {
										api.hideProgress();
										/*   alert('网络错误！');
										      原弹窗提示*/
										api.toast({
											msg: '通霸云影视提醒！网络错误 请检查！'
										});
										//alert( JSON.stringify( err ) );
										return;
									}
								});



							}
						} else {
							api.hideProgress();
							api.alert({
								title: '糟糕~',
								msg: '网络错误！',
							});
						}
					});

				}
			});




		}

		//页面传参
		function openLogin() {
			var delay = 0;
			if (api.systemType != 'ios') {
				delay = 300;
			}


			api.openWin({
				name: 'login',
				url: './login.html',
				pageParam: {
					user: user,
					pass: pass
				},
			});
		}

		//获取验证码
		function getCode() {
			var yzcode = $api.val($api.byId('yzcode'));
			var btn1 = $api.byId('btn1');
			var username = $api.val($api.byId('username'));
			localStorage.setItem('reg_name', username);
			if (!onoff) {
				return;
			}
			onoff = false;

			if (username == '') {
				api.alert({
					title: '警告！',
					msg: '请输入手机号码',
				});
				onoff = true;
				return;
			}
			if (username.length != 11) {
				api.alert({
					title: '警告！',
					msg: '请输入11位手机号码',
				});
				onoff = true;
				return;
			}
			var moduleSMSSDK = api.require('smssdk');
			var param = {
				zone: '86',
				phoneNumber: username,
				tempCode: ''
			};
			moduleSMSSDK.getTextCode(param, function(ret, err) {
				if (err !== null && err !== undefined && err !== '') {
					// 错误消息示例：{"msg":"Template not exist.","code":484}
					alert("Error:\n" + JSON.stringify(err));
				} else {
					// 正常消息示例：{"smart":false}
					api.toast({
						msg: '发送成功',
						duration: 1000,
						location: 'middle'
					});
					var nuw = 60;
					var timer = setInterval(function() {
						nuw--;
						if (nuw < 1) {
							btn1.value = "获取验证码";
							clearInterval(timer);
							onoff = true;
						} else {
							btn1.value = nuw + 's';
						}
					}, 1000)
				}
			});


		}


		function closeWin() {
			api.closeWin({});
		}

		function openWin(name) {
			var delay = 0;
			if (api.systemType != 'ios') {
				delay = 300;
			}
			api.openWin({
				name: '' + name + '',
				url: '' + name + '.html',
				bounces: false,
				delay: delay,
				slidBackEnabled: true,
				vScrollBarEnabled: false
			});
		}
	</script>



</html>
